<?php session_start();

require_once("../config/sohu_config.php");
require_once("SohuOAuth.php");
require_once("sohu_api.php");

include_once('../../config.inc');
require_once(ROOT.'/database/open_api.php');

function sohu_callback()
{
	$_SESSION['callback_count'] ++;
	
	$request_token = $_SESSION['request_token'];
	unset($_SESSION['request_token']);
	
	$oauth_obj = new SohuOAuth(CONSUMER_KEY, CONSUMER_SECRET, 
		$request_token['oauth_token'], $request_token['oauth_token_secret']);
	$access_token = $oauth_obj->getAccessToken($_REQUEST['oauth_verifier']);
	
	$_SESSION["user_type"] = 3;
	$_SESSION['access_token'] = $access_token;
	$_SESSION["sohu_username"] = sohu_get_username($access_token);
	
	open_login(3, $access_token['oauth_token'], $access_token['oauth_token_secret'], "", $_SESSION["sohu_username"], "");
}

//debug
//print_r($_REQUEST);

sohu_callback();

//debug
// print_r($_SESSION);
	
echo "<script>opener.location.reload();window.close();</script>";
?>